<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/img/iconfont.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/img/iconfont.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/img/iconfont.png">
  <link rel="mask-icon" href="/img/iconfont.png" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css" integrity="sha256-VHqXKFhhMxcpubYf9xiWdCiojEbY9NexQ4jh8AxbvcM=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wang-weijun.github.io","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.26.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"codeblock":{"theme":{"light":"default","dark":"stackoverflow-dark"},"prism":{"light":"prism","dark":"prism-dark"},"copy_button":{"enable":false,"style":null},"fold":{"enable":false,"height":500},"language":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.json","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js" defer></script>

    <meta name="description" content="内网穿透常用策略">
<meta property="og:type" content="article">
<meta property="og:title" content="内网穿透">
<meta property="og:url" content="http://wang-weijun.github.io/2024/07/22/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/index.html">
<meta property="og:site_name" content="Phils的杂货铺">
<meta property="og:description" content="内网穿透常用策略">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://wang-weijun.github.io/images/202408071745802.png">
<meta property="og:image" content="http://wang-weijun.github.io/images/202408081206765.png">
<meta property="og:image" content="http://wang-weijun.github.io/images/202410171028627.png">
<meta property="og:image" content="http://wang-weijun.github.io/images/202410171030470.png">
<meta property="og:image" content="http://wang-weijun.github.io/images/202410171039460.png">
<meta property="article:published_time" content="2024-07-22T09:28:45.000Z">
<meta property="article:modified_time" content="2025-11-21T08:58:26.678Z">
<meta property="article:author" content="Phils">
<meta property="article:tag" content="Zerotier">
<meta property="article:tag" content="内网穿透">
<meta property="article:tag" content="Natapp">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://wang-weijun.github.io/images/202408071745802.png">


<link rel="canonical" href="http://wang-weijun.github.io/2024/07/22/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://wang-weijun.github.io/2024/07/22/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/","path":"2024/07/22/内网穿透/","title":"内网穿透"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>内网穿透 | Phils的杂货铺</title>
  








  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.5.0/search.js" integrity="sha256-xFC6PJ82SL9b3WkGjFavNiA9gm5z6UBxWPiu4CYjptg=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>







  





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Phils的杂货铺</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Zerotier"><span class="nav-number">1.</span> <span class="nav-text">Zerotier</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E5%BA%94%E7%94%A8"><span class="nav-number">1.1.</span> <span class="nav-text">安装应用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8D%B8%E8%BD%BD%E5%BA%94%E7%94%A8"><span class="nav-number">1.2.</span> <span class="nav-text">卸载应用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A0%E5%85%A5%E7%BD%91%E7%BB%9C%E8%8A%82%E7%82%B9"><span class="nav-number">1.3.</span> <span class="nav-text">加入网络节点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE-Moon%EF%BC%8C%E5%8A%A0%E9%80%9F%E7%BD%91%E7%BB%9C"><span class="nav-number">1.4.</span> <span class="nav-text">配置 Moon，加速网络</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8-Moon"><span class="nav-number">1.5.</span> <span class="nav-text">使用 Moon</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E6%A0%B9%E8%8A%82%E7%82%B9-Planet"><span class="nav-number">1.6.</span> <span class="nav-text">创建根节点 Planet</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85"><span class="nav-number">1.6.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8A%A0%E5%85%A5%E6%A0%B9%E8%8A%82%E7%82%B9"><span class="nav-number">1.6.2.</span> <span class="nav-text">加入根节点</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Natapp"><span class="nav-number">2.</span> <span class="nav-text">Natapp</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%B3%A8%E5%86%8C%E7%94%A8%E6%88%B7"><span class="nav-number">2.1.</span> <span class="nav-text">1.注册用户</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%B4%AD%E4%B9%B0%E5%85%8D%E8%B4%B9%E9%9A%A7%E9%81%93"><span class="nav-number">2.2.</span> <span class="nav-text">2.购买免费隧道</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BF%AE%E6%94%B9%E9%9A%A7%E9%81%93"><span class="nav-number">2.3.</span> <span class="nav-text">3.修改隧道</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%B8%8B%E8%BD%BD-natapp-%E5%BA%94%E7%94%A8"><span class="nav-number">2.4.</span> <span class="nav-text">4.下载 natapp 应用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E9%85%8D%E7%BD%AE%E5%BA%94%E7%94%A8"><span class="nav-number">2.5.</span> <span class="nav-text">5.配置应用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E8%BF%90%E8%A1%8C%E5%BA%94%E7%94%A8"><span class="nav-number">2.6.</span> <span class="nav-text">6.运行应用</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Phils"
      src="/img/profile.png">
  <p class="site-author-name" itemprop="name">Phils</p>
  <div class="site-description" itemprop="description">个人博客，IT，技术分享</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">40</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">40</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wang-weijun" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wang-weijun" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1191206969@qq.com" title="E-Mail → mailto:1191206969@qq.com" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://wang-weijun.github.io/2024/07/22/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/img/profile.png">
      <meta itemprop="name" content="Phils">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Phils的杂货铺">
      <meta itemprop="description" content="个人博客，IT，技术分享">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="内网穿透 | Phils的杂货铺">
      <meta itemprop="description" content="内网穿透常用策略">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          内网穿透
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-07-22 17:28:45" itemprop="dateCreated datePublished" datetime="2024-07-22T17:28:45+08:00">2024-07-22</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2025-11-21 16:58:26" itemprop="dateModified" datetime="2025-11-21T16:58:26+08:00">2025-11-21</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B7%A5%E5%85%B7/" itemprop="url" rel="index"><span itemprop="name">工具</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B7%A5%E5%85%B7/%E7%BD%91%E7%BB%9C/" itemprop="url" rel="index"><span itemprop="name">网络</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">内网穿透常用策略</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h1 id="Zerotier"><a href="#Zerotier" class="headerlink" title="Zerotier"></a>Zerotier</h1><p>Zerotier 是一款开源工具，可以用来构建基于点对点（P2P）连接的虚拟专用网（VPN）。把各种设备加入相同的虚拟网络，就可以在任何有网络的地方实现网络内的设备互访。官网：<a target="_blank" rel="noopener" href="https://www.zerotier.com/">https://www.zerotier.com/</a></p>
<p>首先通过访问：<a target="_blank" rel="noopener" href="https://my.zerotier.com/">ZeroTier Central</a>，创建一个自己的网络，并记录自己的<strong>Network ID</strong></p>
<h2 id="安装应用"><a href="#安装应用" class="headerlink" title="安装应用"></a>安装应用</h2><p>访问页面：<a target="_blank" rel="noopener" href="https://www.zerotier.com/download/">Download - ZeroTier</a>，进行下载</p>
<p><strong>Windows：</strong></p>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://download.zerotier.com/dist/ZeroTier%20One.msi">https://download.zerotier.com/dist/ZeroTier%20One.msi</a></p>
</blockquote>
<p><strong>Linux：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -s https://install.zerotier.com | <span class="built_in">sudo</span> bash</span><br></pre></td></tr></table></figure>

<p>安装成功后，通过一下命令检验：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">root@jd ~$ zerotier-cli info</span><br><span class="line">200 info b35ec77777 1.14.0 ONLINE</span><br></pre></td></tr></table></figure>

<h2 id="卸载应用"><a href="#卸载应用" class="headerlink" title="卸载应用"></a>卸载应用</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 通过dpkg删除zerotier-one服务</span></span><br><span class="line"><span class="built_in">sudo</span> dpkg -P zerotier-one</span><br><span class="line"><span class="comment"># 删除zerotier-one文件夹，该文件夹存储了address地址，删除后再次安装会获得新的address地址</span></span><br><span class="line"><span class="built_in">sudo</span> <span class="built_in">rm</span> -rf /var/lib/zerotier-one/</span><br></pre></td></tr></table></figure>

<h2 id="加入网络节点"><a href="#加入网络节点" class="headerlink" title="加入网络节点"></a>加入网络节点</h2><p><strong>Windows：</strong>在状态栏对应用右键，选择加入网络，输入我们的<strong>Network ID</strong>，在页面<a target="_blank" rel="noopener" href="https://my.zerotier.com/">ZeroTier Central</a>中进行授权同意-&gt;<em>Auth</em></p>
<p><strong>Linux：</strong><code>sudo zerotier-cli join Network ID </code>，显示<code>200 join OK</code>则在页面进行授权同意</p>
<h2 id="配置-Moon，加速网络"><a href="#配置-Moon，加速网络" class="headerlink" title="配置 Moon，加速网络"></a>配置 Moon，加速网络</h2><p>zerotier 默认使用全球的服务节点，高峰时刻不稳定，官方也有说明，可以搭建自己的 moon 服务器作为跳板，加速网络。</p>
<p>当有云服务器时，将服务器加入网络，进入服务器程序所在目录，默认为：<code>/var/lib/zerotier-one</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /var/lib/zerotier-one</span><br></pre></td></tr></table></figure>

<p>生成<strong>moon.json</strong>配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> zerotier-idtool initmoon identity.public &gt;&gt;moon.json</span><br></pre></td></tr></table></figure>

<p>编辑<strong>moon.json</strong>配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> vim moon.json</span><br></pre></td></tr></table></figure>

<p>将配置文件中的<code>&quot;stableEndpoints&quot;: []</code>修改成<code>&quot;stableEndpoints&quot;: [&quot;ServerIp/9993&quot;]</code>，将<code>ServerIp</code>替换成公网 Ip</p>
<p>生成.moon 文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> zerotier-idtool genmoon moon.json</span><br></pre></td></tr></table></figure>

<p>将生成的 <code>000000xxxxxxxxxx.moon</code>移动到 <code>moons.d</code>目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> <span class="built_in">mkdir</span> moods.d</span><br><span class="line"><span class="built_in">sudo</span> <span class="built_in">cp</span> 000000xxxxxxxxxx.moon moods.d/</span><br></pre></td></tr></table></figure>

<blockquote>
<p>.moon 配置文件名一般为 <code>10个前导零</code> + <code>本机节点ID</code></p>
</blockquote>
<p>重启 zerotier-one 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> systemctl restart zerotier-one.service</span><br></pre></td></tr></table></figure>

<h2 id="使用-Moon"><a href="#使用-Moon" class="headerlink" title="使用 Moon"></a>使用 Moon</h2><p>在其他设备上</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看设备网络</span></span><br><span class="line"><span class="built_in">sudo</span> zerotier-cli listnetworks</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看设备节点连接情况</span></span><br><span class="line"><span class="built_in">sudo</span> zerotier-cli listpeers</span><br></pre></td></tr></table></figure>

<p>可以通过查看设备节点连接情况，看到节点中有我们配置的 Moon 服务器的节点 ID，但是角色还是<code>LEAF</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">200 listpeers &lt;ztaddr&gt; &lt;path&gt; &lt;latency&gt; &lt;version&gt; &lt;role&gt;</span><br><span class="line">200 listpeers 61777fcf53 - -1 - LEAF</span><br></pre></td></tr></table></figure>

<p>我们以 Moon 的形式将 Moon 服务器节点添加到我们的设备中</p>
<p>先复制 Moon 服务器的 id，通过 <code>zerotier-cli info</code> 查看</p>
<p>复制 Moon 服务器的 <code>/var/lib/zerotier-one/moons.d/</code>到其余服务器相同位置，</p>
<p>如 Windows 系统的 <code>c:\programdata\zerotier\one\moons.d</code> 或 Linux 系统的 <code>/var/lib/zerotier-one/moons.d/</code></p>
<p><strong>Linux：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> zerotier-cli orbit 服务器<span class="built_in">id</span> 服务器<span class="built_in">id</span></span><br><span class="line"><span class="comment"># 例如：sudo zerotier-cli orbit b35ec77777 b35ec77777</span></span><br><span class="line"><span class="comment">#返回结果</span></span><br><span class="line">200 orbit OK</span><br><span class="line">// 重启</span><br><span class="line">systemctl restart zerotier-one</span><br></pre></td></tr></table></figure>

<p>**Windows:**通过管理员运行 cmd</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">zerotier-cli.bat orbit 服务器<span class="built_in">id</span> 服务器<span class="built_in">id</span></span><br></pre></td></tr></table></figure>

<p>在服务管理中重启</p>
<p>配置完成后，更改路由：</p>
<p><img src="/../images/202408071745802.png" alt="image-20240807174501747"></p>
<blockquote>
<p>说明 1： 192.168.196.0&#x2F;24，局域网网段</p>
<p>说明 2： 把所有主机的局域网 IP 都加上去，例如我有 3 个</p>
<p>说明 3： 路由生效存在延迟，多 ping 几次</p>
<p>说明 4： ping 技巧： 主机优先 ping 公网的内网 IP，然后逐个 ping 其他主机的 IP；每个主机都执行一次，速度就上来了</p>
<p>说明 5： 把默认的删除掉，不然还会走默认的路由</p>
</blockquote>
<h2 id="创建根节点-Planet"><a href="#创建根节点-Planet" class="headerlink" title="创建根节点 Planet"></a>创建根节点 Planet</h2><p>创建根节点 Planet 需要有一个云服务器，并且拥有公网 Ip</p>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><p>我们使用 docker 安装：<a target="_blank" rel="noopener" href="https://ztnet.network/">ZTNet - Zerotier Web UI Documentation</a>、postgres（数据库）、zerotier</p>
<p>安装 Docker，Docker Compose 后，创建一个 docker-compose.yml 文件</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">postgres:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">postgres:15.2-alpine</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">postgres</span></span><br><span class="line">    <span class="attr">restart:</span> <span class="string">unless-stopped</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">      <span class="attr">POSTGRES_USER:</span> <span class="string">postgres</span></span><br><span class="line">      <span class="attr">POSTGRES_PASSWORD:</span> <span class="string">postgres</span></span><br><span class="line">      <span class="attr">POSTGRES_DB:</span> <span class="string">ztnet</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">postgres-data:/var/lib/postgresql/data</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">app-network</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">zerotier:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">zyclonite/zerotier:1.14.0</span></span><br><span class="line">    <span class="attr">hostname:</span> <span class="string">zerotier</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">zerotier</span></span><br><span class="line">    <span class="attr">restart:</span> <span class="string">unless-stopped</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">zerotier:/var/lib/zerotier-one</span></span><br><span class="line">    <span class="attr">cap_add:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">NET_ADMIN</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">SYS_ADMIN</span></span><br><span class="line">    <span class="attr">devices:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">/dev/net/tun:/dev/net/tun</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">app-network</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;9993:9993/udp&quot;</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">ZT_OVERRIDE_LOCAL_CONF=true</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">ZT_ALLOW_MANAGEMENT_FROM=172.31.255.0/29</span></span><br><span class="line"></span><br><span class="line">  <span class="attr">ztnet:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">sinamics/ztnet:latest</span></span><br><span class="line">    <span class="attr">container_name:</span> <span class="string">ztnet</span></span><br><span class="line">    <span class="attr">working_dir:</span> <span class="string">/app</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">zerotier:/var/lib/zerotier-one</span></span><br><span class="line">    <span class="attr">restart:</span> <span class="string">unless-stopped</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="number">3000</span><span class="string">:3000</span></span><br><span class="line">    <span class="comment"># - 127.0.0.1:3000:3000  &lt;--- Use / Uncomment this line to restrict access to localhost only</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">      <span class="attr">POSTGRES_HOST:</span> <span class="string">postgres</span></span><br><span class="line">      <span class="attr">POSTGRES_PORT:</span> <span class="number">5432</span></span><br><span class="line">      <span class="attr">POSTGRES_USER:</span> <span class="string">postgres</span></span><br><span class="line">      <span class="attr">POSTGRES_PASSWORD:</span> <span class="string">postgres</span></span><br><span class="line">      <span class="attr">POSTGRES_DB:</span> <span class="string">ztnet</span></span><br><span class="line">      <span class="attr">NEXTAUTH_URL:</span> <span class="string">&quot;http://localhost:3000&quot;</span> <span class="comment"># !! Important !! Set the NEXTAUTH_URL environment variable to the canonical URL or IP of your site with port 3000</span></span><br><span class="line">      <span class="attr">NEXTAUTH_SECRET:</span> <span class="string">&quot;random_secret&quot;</span></span><br><span class="line">      <span class="attr">NEXTAUTH_URL_INTERNAL:</span> <span class="string">&quot;http://ztnet:3000&quot;</span> <span class="comment"># Internal NextAuth URL for &#x27;ztnet&#x27; container on port 3000. Do not change unless modifying container name.</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">app-network</span></span><br><span class="line">    <span class="attr">links:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">postgres</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">postgres</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">zerotier</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">############################################################################</span></span><br><span class="line">  <span class="comment">#                                                                          #</span></span><br><span class="line">  <span class="comment"># Uncomment the section below to enable HTTPS reverse proxy with Caddy.    #</span></span><br><span class="line">  <span class="comment">#                                                                          #</span></span><br><span class="line">  <span class="comment"># Steps:                                                                   #</span></span><br><span class="line">  <span class="comment"># 1. Replace &lt;YOUR-PUBLIC-HOST-NAME&gt; with your actual public domain name.  #</span></span><br><span class="line">  <span class="comment"># 2. Uncomment the caddy_data volume definition in the volumes section.    #</span></span><br><span class="line">  <span class="comment">#                                                                          #</span></span><br><span class="line">  <span class="comment">############################################################################</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># https-proxy:</span></span><br><span class="line">  <span class="comment">#   image: caddy:latest</span></span><br><span class="line">  <span class="comment">#   container_name: ztnet-https-proxy</span></span><br><span class="line">  <span class="comment">#   restart: unless-stopped</span></span><br><span class="line">  <span class="comment">#   depends_on:</span></span><br><span class="line">  <span class="comment">#     - ztnet</span></span><br><span class="line">  <span class="comment">#   command: caddy reverse-proxy --from &lt;YOUR-PUBLIC-HOST-NAME&gt; --to ztnet:3000</span></span><br><span class="line">  <span class="comment">#   volumes:</span></span><br><span class="line">  <span class="comment">#     - caddy_data:/data</span></span><br><span class="line">  <span class="comment">#   networks:</span></span><br><span class="line">  <span class="comment">#     - app-network</span></span><br><span class="line">  <span class="comment">#   links:</span></span><br><span class="line">  <span class="comment">#     - ztnet</span></span><br><span class="line">  <span class="comment">#   ports:</span></span><br><span class="line">  <span class="comment">#     - &quot;80:80&quot;</span></span><br><span class="line">  <span class="comment">#     - &quot;443:443&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">zerotier:</span></span><br><span class="line">  <span class="attr">postgres-data:</span></span><br><span class="line">  <span class="comment"># caddy_data:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">app-network:</span></span><br><span class="line">    <span class="attr">driver:</span> <span class="string">bridge</span></span><br><span class="line">    <span class="attr">ipam:</span></span><br><span class="line">      <span class="attr">driver:</span> <span class="string">default</span></span><br><span class="line">      <span class="attr">config:</span></span><br><span class="line">        <span class="bullet">-</span> <span class="attr">subnet:</span> <span class="number">172.31</span><span class="number">.255</span><span class="number">.0</span><span class="string">/29</span></span><br></pre></td></tr></table></figure>

<p>或者直接下载：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget -O docker-compose.yml https://raw.githubusercontent.com/sinamics/ztnet/main/docker-compose.yml</span><br></pre></td></tr></table></figure>

<p>更改<code>docker-compose.yml</code>，设置默认服务器 IP</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="string">...</span></span><br><span class="line">  <span class="attr">ztnet:</span></span><br><span class="line">    <span class="string">...</span></span><br><span class="line">    <span class="attr">environment:</span></span><br><span class="line">	  <span class="string">...</span></span><br><span class="line">      <span class="attr">NEXTAUTH_URL:</span> <span class="string">&quot;http://公网Ip:3000&quot;</span></span><br></pre></td></tr></table></figure>

<p>启动 docker：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker compose up -d</span><br></pre></td></tr></table></figure>

<p>放开服务器<code>3000</code>端口，访问 <code>http://公网ip:3000</code>，进行注册，注册的一个用户为管理员</p>
<p>然后点击<code>设置</code>-》<code>控制器</code>，在最下面创建自定义星球，输入公网 ip，点击创建，点击下载 <code>api/planet</code>,保存好文件</p>
<p><img src="/../images/202408081206765.png" alt="image-20240808120630699"></p>
<h3 id="加入根节点"><a href="#加入根节点" class="headerlink" title="加入根节点"></a>加入根节点</h3><p>这里主要以<code>Windows</code>和<code>Linux</code>演示加入，分别设备下载好 zerotier 客户端，<a target="_blank" rel="noopener" href="https://www.zerotier.com/download/">Download - ZeroTier</a></p>
<p>将刚才保存的<code>planet</code>文件，分别覆盖到：</p>
<ul>
<li>Windows：<code>C:\ProgramData\ZeroTier\One</code> 路径下</li>
<li>Linux：<code>/var/lib/zerotier-one</code> 路径下</li>
</ul>
<p>重启服务：</p>
<ul>
<li>windows：<code>win + R</code>，输入<code>services.msc</code>，找到<code>ZeroTier One</code>-》重启动</li>
<li>Linux：<code>systemctl restart zerotier-one</code></li>
</ul>
<p>使用命令查看根节点是否只有自己的一个：<code>zerotier-cli peers</code>,可以看到只有一个<code>PLANET</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ zerotier-cli peers</span><br><span class="line">200 peers</span><br><span class="line">&lt;ztaddr&gt;   &lt;ver&gt;  &lt;role&gt; &lt;lat&gt; &lt;<span class="built_in">link</span>&gt;   &lt;lastTX&gt; &lt;lastRX&gt; &lt;path&gt;</span><br><span class="line">b740eaaaee 1.14.0 PLANET    21 DIRECT   942      15       公网Ip/9993</span><br></pre></td></tr></table></figure>

<p>然后我们加入网络节点，在 Web 管理页面，选择<code>本地控制器</code>-&gt; <code>创建网络</code>-&gt;<code>复制网络ID</code></p>
<p>在设备中加入网络：<code>zerotier-cli join 网络ID</code></p>
<h1 id="Natapp"><a href="#Natapp" class="headerlink" title="Natapp"></a>Natapp</h1><p>将自己开发的机器上的应用提供到公网上进行访问，但是并不想通过注册域名、搭建服务器；由此可以使用 natapp（内网穿透）</p>
<h2 id="1-注册用户"><a href="#1-注册用户" class="headerlink" title="1.注册用户"></a>1.注册用户</h2><p>进入官网后进行注册：<a target="_blank" rel="noopener" href="https://natapp.cn/">https://natapp.cn</a></p>
<h2 id="2-购买免费隧道"><a href="#2-购买免费隧道" class="headerlink" title="2.购买免费隧道"></a>2.购买免费隧道</h2><p><img src="/../images/202410171028627.png" alt="image-20241017102816408"></p>
<h2 id="3-修改隧道"><a href="#3-修改隧道" class="headerlink" title="3.修改隧道"></a>3.修改隧道</h2><p><img src="/../images/202410171030470.png" alt="image-20241017103053348"></p>
<h2 id="4-下载-natapp-应用"><a href="#4-下载-natapp-应用" class="headerlink" title="4.下载 natapp 应用"></a>4.下载 natapp 应用</h2><p>下载对应机型应用：<a target="_blank" rel="noopener" href="https://natapp.cn/#download%EF%BC%8C%E4%B8%8B%E8%BD%BD%E5%A5%BD%E5%90%8E%E8%A7%A3%E5%8E%8B%EF%BC%8C%E5%BE%97%E5%88%B0natapp.exe">https://natapp.cn/#download，下载好后解压，得到natapp.exe</a></p>
<h2 id="5-配置应用"><a href="#5-配置应用" class="headerlink" title="5.配置应用"></a>5.配置应用</h2><p>进行内网穿透还需要配置本地配置文件<strong>config.ini</strong>，参考网址：<a target="_blank" rel="noopener" href="https://natapp.cn/article/config_ini">https://natapp.cn/article/config_ini</a></p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#将本文件放置于natapp同级目录 程序将读取 [default] 段</span></span><br><span class="line"><span class="comment">#在命令行参数模式如 natapp -authtoken=xxx 等相同参数将会覆盖掉此配置</span></span><br><span class="line"><span class="comment">#命令行参数 -config= 可以指定任意config.ini文件</span></span><br><span class="line"><span class="section">[default]</span></span><br><span class="line"><span class="attr">authtoken</span>=取得authtoken（刚刚才购买的隧道） <span class="comment">#对应一条隧道的authtoken</span></span><br><span class="line">clienttoken=                    		<span class="comment">#对应客户端的clienttoken,将会忽略authtoken,若无请留空,</span></span><br><span class="line"><span class="attr">log</span>=none                        		<span class="comment">#log 日志文件,可指定本地文件, none=不做记录,stdout=直接屏幕输出 ,默认为none</span></span><br><span class="line"><span class="attr">loglevel</span>=ERROR                  		<span class="comment">#日志等级 DEBUG, INFO, WARNING, ERROR 默认为 DEBUG</span></span><br><span class="line">http_proxy=                     		<span class="comment">#代理设置 如 http://10.123.10.10:3128 非代理上网用户请务必留空</span></span><br></pre></td></tr></table></figure>

<h2 id="6-运行应用"><a href="#6-运行应用" class="headerlink" title="6.运行应用"></a>6.运行应用</h2><p>将配置文件<strong>config.ini</strong>与<strong>natapp.exe</strong>放在同一个目录下，双击<strong>natapp.exe</strong>启动即可</p>
<p><img src="/../images/202410171039460.png" alt="image-20241017103911386"></p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Zerotier/" rel="tag"># Zerotier</a>
              <a href="/tags/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" rel="tag"># 内网穿透</a>
              <a href="/tags/Natapp/" rel="tag"># Natapp</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2024/06/05/Zabbix%E8%BF%90%E7%BB%B4%E5%B9%B3%E5%8F%B0/" rel="prev" title="运维平台">
                  <i class="fa fa-angle-left"></i> 运维平台
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2024/09/15/%E4%B8%B2%E6%B5%81%E6%95%99%E7%A8%8B/" rel="next" title="串流教程">
                  串流教程 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Phils</span>
  </div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>

</body>
</html>
